package com.atguigu.gmall.seckill.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.seckill.service.SecKillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/10/20 4:37
 */
@RestController
@RequestMapping("/api/activity/seckill/auth")
public class SecKillController {
    @Autowired
    SecKillService secKillService;

    ///api/activity/seckill/auth/getSeckillSkuIdStr/38
    //请求方法:
    //GET
    @GetMapping("/getSeckillSkuIdStr/{skuId}")
    public Result<String> getSeckillSkuIdStr(@PathVariable("skuId") Long skuId) {
        String str = secKillService.getSeckillSkuIdStr(skuId);
        return Result.ok(str);
    }

    ///seckillOrder/null?skuIdStr=null
    //请求方法: 秒杀下单
    //POST
    @PostMapping("/seckillOrder/{skuId}")
    public Result seckillOrder(@PathVariable("skuId") Long skuId
            , @RequestParam("skuIdStr") String skuIdStr) throws InterruptedException {
        secKillService.ajaxSeckillOrder(skuId, skuIdStr);
        return Result.ok();
    }
    @GetMapping("/checkOrder/{skuId}")
    public Result checkSeckillOrder(@PathVariable("skuId") Long skuId) {
        ResultCodeEnum resultCodeEnum = secKillService.checkSeckillOrder(skuId);
        return Result.build("",resultCodeEnum);
    }
}
